<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use function Symfony\Component\VarDumper\Dumper\esc;

class TopicFocusModel extends Model
{
    protected $table = 'topic_focus';
    public $timestamps = false;
    protected $guarded = [];

    public function getALLJoinDate( $topic_id)
    {
       $res =  DB::table('topic_focus') ->where(['topic_id' => $topic_id]) ->count();
       if($res){
           return ['code' => true,'data' => $res ];
       }else{
            return ['code' => false,'data' => '数据为空！'];
       }

    }

    public function getTopicFocusStatue($user_id, $topic_id)
    {
       $res =  TopicFocusModel::where(['user_id' =>$user_id,'topic_id' => $topic_id]) ->get();

       if(count($res) > 0){
           return ['code' => true, 'data' => 1];//关注
       }else{
           return ['code' => true, 'data' => 0];//未关注
       }

    }

    public function SaveFocusTopic($user_id, $topic_id)
    {

        $res =   TopicFocusModel::create([
            'user_id' => $user_id,
            'topic_id' => $topic_id,
            'created_tiem' => date('Y:m:d H:i:s'),
        ]);

        if($res){
            return ['code' => true, 'data' => '关注成功！'];//未关注
        }else{
            return ['code' => false, 'data' => '关注失败！'];//未关注
        }

    }

    public function deletedFocusTopic($user_id, $topic_id)
    {
      $res =   DB::table('topic_focus') ->where(['user_id' =>$user_id,'topic_id' =>$topic_id]) ->delete();
      if($res){
          return ['code' => true,'data' => '取消成功！'];
      }else{
          return ['code' => true,'data' => '取消失败！'];
      }
    }




}
